/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SwingAnimation;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JComponent;

/**
 *
 * @author Heather
 */
public class ArrowComponent extends JComponent
{
  private Image buffer;
  private Graphics bufferG;

  public ArrowComponent()
  {
    super();
    this.setBackground(Color.red);
  }

  private void drawArrow(Graphics g)
  {
    bufferG.setColor(this.getBackground());
    bufferG.fillRect(0, 0, this.getWidth(), this.getHeight());
  }

  @Override
  public void paint(Graphics g)
  {
    // This creates the buffer
    if (buffer == null)
    {
      int xBound = getSize().width;
      int yBound = getSize().height;

      buffer = this.createImage(xBound, yBound);
      bufferG = buffer.getGraphics();
      bufferG.setColor(Color.white);
      bufferG.fillRect(0, 0, xBound, yBound);
    }
    g.drawImage(buffer, 0, 0, this);
    drawArrow(g);
  }
}
